﻿Imports System.Data.SqlClient
Public Class FormCustomerEditor

    
    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Cmd.Parameters("@CustomerName") = Me.txtCustomerName.Text
        Cmd.Parameters("@Phone") = Me.txtPhone.Text
        Cmd.Parameters("@Address") = Me.txtAddress.Text 
        If Me.txtCustomerId.Text = "" Then
            Cmd.ExecuteNonQuery("INSERT INTO Customer VALUES(@CustomerName,@Phone,@Address,1);")
        Else
            Cmd.Parameters("@CustomerId") = txtCustomerId.Text
            Cmd.ExecuteNonQuery("UPDATE Customer SET CustomerName=@CustomerName,Phone=@Phone,Address=@Address WHERE CustomerId=@CustomerId")
        End If

        Me.DialogResult = Windows.Forms.DialogResult.OK

    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

        Me.DialogResult = Windows.Forms.DialogResult.Cancel

    End Sub
End Class